using CHSystemApi.Business;
using CHSystemApi.DataAccess.Entities;
using CHSystemApi.Framework.AuthServices;
using CHSystemApi.Framework.Base;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;

namespace CHSystemApi.Base.Controllers
{
    public class PermissionController : BaseController
    {
        public IPermissionBusiness _business;

        private IPermissionService _permissionService;

        public PermissionController(IPermissionBusiness business, IPermissionService permissionService)
        {
            _business = business;
            _permissionService = permissionService;
        }

        [Authorize]
        [HttpGet("/openapi/v1/1.0.1/permission/get")]
        public BaseResponse GetPermission()
        {
            return OK(_permissionService
            .ValidatePermission<IPermissionBusiness>(new List<PermissionContent>() { new PermissionContent() { Content = "/openapi/v1/1.0.1/permission/add", Type = Framework.CustomType.PermissionType.接口访问权限 } })
            .GetPermissions());
        }

        [HttpPost("/openapi/v1/1.0.1/permission/add")]
        public BaseResponse AddPermission()
        {
            return AjaxResult(
            _permissionService
            .ValidatePermission<IPermissionBusiness>(new List<PermissionContent>() { new PermissionContent() { Content = "/openapi/v1/1.0.1/permission/get", Type = Framework.CustomType.PermissionType.接口访问权限 } })
            .AddPermission(new Permission()),
            (x) =>
            {
                if (x)
                    return Framework.Extension.StatusCode.OK;
                return Framework.Extension.StatusCode.Internal_Server_Error;
            });
        }
    }
}
